package com.example.adapter;

import java.util.ArrayList;

import com.example.bai12.R;
import com.example.object.NhanVien;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NhanVienAdapter extends ArrayAdapter<NhanVien>{

	Activity context;
	int layoutid;
	ArrayList<NhanVien> arr;
	public NhanVienAdapter(Activity context,
			int textViewResourceId, ArrayList<NhanVien> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		this.context=context;
		this.layoutid=textViewResourceId;
		this.arr=objects;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		convertView= this.context.getLayoutInflater().inflate(layoutid, null);
		TextView txtshortinfo=(TextView) convertView.findViewById(com.example.bai12.R.id.txtshortinfo);
		TextView txtdetailinfo=(TextView) convertView.findViewById(com.example.bai12.R.id.txtdetailinfo);
		ImageView imgview= (ImageView) convertView.findViewById(R.id.imgview);
		
		NhanVien nv= arr.get(position);
		if(nv.isGioitinh())
		{
			imgview.setImageResource(R.drawable.girl);
		}
		else
		{
			imgview.setImageResource(R.drawable.boy);
		}
		txtshortinfo.setText(nv.toString());
		
		String strMota="";
		 String cv="Chức vụ: "+nv.getChucvu().getChucVu();
		 String gt="Giới tính: "+(nv.isGioitinh()?"Nữ":"Nam");
		 strMota=cv+"\n"+gt;
		 txtdetailinfo.setText(strMota);
		 
		return convertView;
	}

}
